# 给你一个 m x n 的矩阵 M 和一个操作数组 op 。矩阵初始化时所有的单元格都为 0 。ops[i] = [ai, bi] 意味着当所有的 0 <= 
# x < ai 和 0 <= y < bi 时， M[x][y] 应该加 1。 
# 
#  在 执行完所有操作后 ，计算并返回 矩阵中最大整数的个数 。 
# 
#  
# 
#  示例 1: 
# 
#  
# 
#  
# 输入: m = 3, n = 3，ops = [[2,2],[3,3]]
# 输出: 4
# 解释: M 中最大的整数是 2, 而且 M 中有4个值为2的元素。因此返回 4。
#  
# 
#  示例 2: 
# 
#  
# 输入: m = 3, n = 3, ops = [[2,2],[3,3],[3,3],[3,3],[2,2],[3,3],[3,3],[3,3],[2,2]
# ,[3,3],[3,3],[3,3]]
# 输出: 4
#  
# 
#  示例 3: 
# 
#  
# 输入: m = 3, n = 3, ops = []
# 输出: 9
#  
# 
#  
# 
#  提示: 
# 
#  
#  
# 
#  
#  1 <= m, n <= 4 * 10⁴ 
#  0 <= ops.length <= 10⁴ 
#  ops[i].length == 2 
#  1 <= ai <= m 
#  1 <= bi <= n 
#  
# 
#  Related Topics 数组 数学 👍 208 👎 0
from typing import List


# leetcode submit region begin(Prohibit modification and deletion)
from collections import Counter
class Solution:
    def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int:
        """
        if ops:
            arr = [[0]*n for _ in range(m)]
            for i in range(m):
                for j in range(n):
                    for x, y in ops:
                        if 0 <= i < x and 0 <= j < y:
                            arr[i][j] += 1
            list = [x for row in arr for x in row]
            return Counter(list)[max(list)]

        else:
            return m*n
        """
        if ops:
            minx = min([op[0] for op in ops])
            miny = min([op[1] for op in ops])
            return minx*miny
        else:
            return m*n

# leetcode submit region end(Prohibit modification and deletion)
print(Solution().maxCount(m=39999, n=39999, ops=[[19999,19999]]))
